package net.lab0.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Extracted from my personal utilities:
 * https://code.google.com/p/uuh116/source/browse/#svn%2Ftrunk%2Ftools%2Fsrc%2Fnet%2Flab0%2Ftools%253Fstate%253Dclosed
 * 
 * @author 116@lab0.net
 * 
 */
public class FileUtils
{
    /**
     * Reads a text file line by line
     * 
     * @param input
     *            The file to read
     * @return a List of Strings, the data read in the file, line by line
     * @throws IOException
     */
    public static List<String> readFileAsText(File input)
    throws IOException
    {
        FileReader fileReader = new FileReader(input);
        BufferedReader bufferedReader = null;
        
        List<String> lines = new ArrayList<String>();
        String line = null;
        try
        {
            bufferedReader = new BufferedReader(fileReader);
            while ((line = bufferedReader.readLine()) != null)
            {
                lines.add(line);
            }
        }
        finally
        {
            if (bufferedReader != null)
            {
                bufferedReader.close();
            }
        }
        return lines;
    }
}
